/**
  涉及到星星图像排序
**/

import React from 'react'
import { Rate } from 'antd'

export default class Star extends React.PureComponent {
  static defaultProps = {
    value: ''
  }

  /**
   *grade
  -2不评级
  -1 卖出
  0空
  [1,2,3,4] 星星
  取gradHtml的值或者接取grade的值
   */
  renderStar = (value) => {
    let ele = null
    const data = []
    if (value === '-' || value === null || value === undefined) {
      return '-'
    }
    let num = Number(value.slice(-7).slice(0, 1))
    if (isNaN(num)) {
      num = Number(value) //修复上一步取负数到-
    }
    switch (num) {
      case -2:
        ele = '不评级'
        break
      case -1:
        ele = '卖出'
        break
      case 0:
        ele = ''
        break
      default:
        ele = <Rate allowHalf defaultValue={num} />
        break
    }
    return ele
  }

  render() {
    const { value } = this.props
    return (
      <div className="star" onClick={this.props.onClick}>
        {this.renderStar(value)}
      </div>
    )
  }
}
